<?php if($this->errMsg) :?>
	<?php $this->showError($this->errMsg)?>
<?php endif; ?>
<style>

</style>
<form action=""  id="fr" name='fr' method="post"> 
	<div class="title_ad"><label><a href="">Danh sách User</a></label>
	<a style="text-align:right;float:right;margin-right:20px;" href=""><img src="<?php echo $this->baseUrl()?>/application/templates/admin/images/plus_32.png" /></a></div>
	<table  class="display" id="list">
	<thead>
		<tr>
			<th width="10px">ID</th>
			<th>UserName</th>
			<th>Name</th>
			<th>Email</th>
			<th>Phone</th>
			<th>Group</th>
			<th width="130px">Status</th>
			<th width="80px" style="text-align: center;">Tool</th>
		</tr>
	</thead>
	<tbody>
	
	<?php
		foreach($this->data as $row)
		{ 
			if($row->id != 1)
			{
			$active = "";
			if($row->active =='1')
				$active = 'Kích hoạt <a style="float:right;" href="javascript:banned('.$row->id.')" title="Khóa user này" class="Banned"><img src="'.$this->baseUrl().'/public/images/Unbanned.png"></img></a>';
			else
				$active = 'Chưa kích hoạt <a style="float: right;" href="javascript:unbanned('.$row->id.')" title="kích hoạt user này" class="Unbanned"><img src="'.$this->baseUrl().'/public/images/Banned.png"></img></a>';
	?>
		<tr>
			<td width="60"><?php echo $row->id?></td>
			<td><?php echo $row->userName;?></td>
			<td><?php echo $row->name;?></td>
			<td><?php echo $row->email;?></td>
			<td><?php echo $row->phone;?></td>
			<td><?php echo $row->gname;?></td>
			<td id="active_<?php echo $row->id;?>"><?php echo $active;?></td>
			<td>
				<a href="<?php echo $this->baseUrl()?>/admin/user/edit/id/<?php echo $row->id;?>" title='Edit' class='tool-16 edit'></a>&nbsp;&nbsp;
				<a href="javascript:del(<?php echo $row->id;?>)" title='Delete' class='tool-16 delete'></a>
			</td>
		</tr>		
	<?php
			}
			else
			{
				echo('
				<tr>
				<td width="60">'.$row->id.'</td>
				<td>'.$row->userName.'</td>
				<td>'.$row->name.'</td>
				<td>'.$row->email.'</td>
				<td>'.$row->phone.'</td>
				<td>'.$row->gname.'</td>
				<td></td>
				<td ><a href="'.$this->baseUrl().'/admin/user/edit/id/1" title="Edit" class="tool-16 edit"></a>&nbsp;&nbsp;</td>
				</tr>');
			}
		} 		
	?>
	</tbody>
</table>
</form>
<script>
function banned(key){
	if(!confirm("bạn muốn khóa tài khoản này không??"))
		return;
	$.ajax({
		type: "POST",
		url:"<?php echo $this->baseUrl.'/admin/user/active'?> ",
		data: "id=" + key +"&active=0",	
		success: function(msg)
		{
			if(msg == "1")
				$('#active_'+key).html('Chưa kích hoạt<a style="float: right;" href="javascript:unbanned('+key+')" title="Kích hoạt user này" class="Unbanned"><img src="<?php echo ($this->baseUrl().'/public/images/Banned.png');?>"></img></a>');
			else
				alert('Error');
		}
	});
}

function unbanned(key){
	if(!confirm("bạn muốn kích hoạt tài khoản này không?"))
		return;
	$.ajax({
		type: "POST",
		url:"<?php echo $this->baseUrl.'/admin/user/active'?> ",
		data: "id=" + key +"&active=1",	
		success: function(msg){	
			if(msg == "1")	
				$('#active_'+key).html('Kích hoạt<a style="float: right;" href="javascript:banned('+key+')" title="khóa user này" class="Banned"><img src="<?php echo ($this->baseUrl().'/public/images/Unbanned.png') ?>"></img></a>');
			else
				alert('Error');
		}
	});
}
function del(key){
	if(!confirm("Bạn muốn xóa user này không??"))
		return;
	$.ajax({
		type: "POST",
		url:"<?php echo $this->baseUrl.'/admin/user/active'?> ",
		data: "id=" + key +"&active=-1",	
		success: function(msg){
			if(msg == '1')
				location.replace("<?php echo $this->baseUrl.'/admin/user/index'?>");
			else
				alert('Error');
		}
	});
} 
</script>